package com.yeyks.commonReference.service.hotel.impl;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yeyks.account.dal.domain.AccountInfo;
import com.yeyks.account.utils.AccountUtil;
import com.yeyks.common.appcommon.dto.finance.AppFinanceStatusDTO;
import com.yeyks.common.appcommon.param.finance.QueryWithdrawalOrderParam;
import com.yeyks.common.appcommon.result.CommonPage;
import com.yeyks.common.appcommon.result.CommonResult;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.base.PageResult;
import com.yeyks.common.constants.AccountType;
import com.yeyks.common.dto.AccountPayAccountDTO;
import com.yeyks.common.dto.NewPayAmountDTO;
import com.yeyks.common.em.accountinfo.AccountInfoTypeEnum;
import com.yeyks.common.exception.ServiceException;
import com.yeyks.common.param.WithdrawalOrderParam;
import com.yeyks.common.param.finance.*;
import com.yeyks.common.result.withdrawalorder.*;
import com.yeyks.common.utils.*;
import com.yeyks.common.utils.apputil.bean.MyBeanUtils;
import com.yeyks.common.utils.apputil.enums.FinanceStatusEnum;
import com.yeyks.commonReference.append.sms.SmsService;
import com.yeyks.commonReference.service.account.AccountInfoService;
import com.yeyks.commonReference.service.hotel.HotelAccountOverviewService;
import com.yeyks.commonReference.service.hotel.HotelInfoService;
import com.yeyks.commonReference.service.hotel.HotelWithdrawalOrderService;
import com.yeyks.commonReference.service.vip.MiniVipCommissionBillService;
import com.yeyks.commonReference.service.vip.MiniVipCommissionOverviewService;
import com.yeyks.commonReference.service.vip.VipCommissionBillService;
import com.yeyks.commonReference.service.vip.VipCommissionOverviewService;
import com.yeyks.hotel.dal.dao.HotelWithdrawalOrderMapper;
import com.yeyks.hotel.dal.domain.HotelAccountOverview;
import com.yeyks.hotel.dal.domain.HotelInfo;
import com.yeyks.hotel.dal.domain.HotelWithdrawalOrder;
import com.yeyks.commonReference.service.mattress.HotelMattressOverviewService;
import com.yeyks.vip.dal.domain.MiniVipCommissionOverview;
import com.yeyks.vip.dal.domain.VipCommissionOverview;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.*;

/**
 * 酒店房费提现订单表 服务实现类
 *
 * @author shuai
 * @date 2019-07-08
 */
@Service
@Slf4j
public class HotelWithdrawalOrderServiceImpl extends ServiceImpl<HotelWithdrawalOrderMapper, HotelWithdrawalOrder> implements HotelWithdrawalOrderService {

    @Autowired
    private HotelInfoService hotelInfoService;
    @Autowired
    private HotelAccountOverviewService hotelAccountOverviewService;
    @Autowired
    private SmsService smsService;
    @Autowired
    private HotelMattressOverviewService overviewService;
    @Autowired
    private AccountInfoService accountInfoService;
    @Autowired
    private VipCommissionBillService vipCommissionBillService;
    @Autowired
    private VipCommissionOverviewService vipCommissionOverviewService;
    @Autowired
    private MiniVipCommissionOverviewService miniVipCommissionOverviewService;
    @Autowired
    private MiniVipCommissionBillService miniVipCommissionBillService;

    /**
     * c2b酒店提现订单查询
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    public PageResult<HotelWithdrawalOrderResult> myC2bHotelList(AccountInfo loginUser, WithdrawalOrderParam param) {
        Map<String, Object> map = myListMap(param);
        map.put("hotelName", param.getHotelName());
        map.put("phone", param.getPhone());
        map.put("accountTypes", Lists.newArrayList(5));
        if (!AccountInfoTypeEnum.Administrator.value().equals(loginUser.getType())) {
            map.put("operatorId", AccountUtil.getOperationUserId(loginUser));
        }
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<HotelWithdrawalOrder> orders = baseMapper.myC2bHotelList(map);
        PageInfo<HotelWithdrawalOrder> pageInfo = PageInfo.of(orders);
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getPages(), pageInfo.isHasNextPage(), pageInfo.getNextPage(), getC2bHotelWithdrawalOrderResult(pageInfo.getList()));
    }

    /**
     * c2b代理提现订单查询
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    public PageResult<AgentWithdrawalOrderResult> myC2bAgentList(AccountInfo loginUser, WithdrawalOrderParam param) {
        Map<String, Object> map = myListMap(param);
        map.put("operatorName", param.getOperatorName());
        map.put("operatorPhone", param.getOperatorPhone());
        if (!AccountInfoTypeEnum.Administrator.value().equals(loginUser.getType())) {
            map.put("operatorId", AccountUtil.getOperationUserId(loginUser));
            map.put("accountTypes", Lists.newArrayList(loginUser.getType()));
        } else {
            map.put("accountTypes", Lists.newArrayList(2, 3, 4));
        }
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<HotelWithdrawalOrder> orders = baseMapper.myC2bAgentList(map);
        PageInfo<HotelWithdrawalOrder> pageInfo = PageInfo.of(orders);
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getPages(), pageInfo.isHasNextPage(), pageInfo.getNextPage(), getC2bAgentWithdrawalOrderResult(pageInfo.getList()));
    }

    /**
     * 床垫酒店提现订单查询
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    public PageResult<HotelWithdrawalOrderResult> myMattressHotelList(AccountInfo loginUser, WithdrawalOrderParam param) {
        return myC2bHotelList(loginUser, param);
    }

    /**
     * 床垫代理提现订单查询
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    public PageResult<AgentWithdrawalOrderResult> myMattressAgentList(AccountInfo loginUser, WithdrawalOrderParam param) {
        return myC2bAgentList(loginUser, param);
    }

    /**
     * vip酒店提现订单查询
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    public PageResult<HotelWithdrawalOrderResult> myVipHotelList(AccountInfo loginUser, WithdrawalOrderParam param) {
        return myC2bHotelList(loginUser, param);
    }

    /**
     * vip运营商提现订单查询
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    public PageResult<AgentWithdrawalOrderResult> myVipOperatorList(AccountInfo loginUser, WithdrawalOrderParam param) {
        Map<String, Object> map = myListMap(param);
        map.put("operatorName", param.getOperatorName());
        map.put("operatorPhone", param.getOperatorPhone());
        if (!AccountInfoTypeEnum.Administrator.value().equals(loginUser.getType())) {
            map.put("operatorId", AccountUtil.getOperationUserId(loginUser));
            map.put("accountTypes", Lists.newArrayList(loginUser.getType()));
        } else {
            map.put("accountTypes", Lists.newArrayList(10, 11, 12));
        }
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<HotelWithdrawalOrder> orders = baseMapper.myC2bAgentList(map);
        PageInfo<HotelWithdrawalOrder> pageInfo = PageInfo.of(orders);
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getPages(), pageInfo.isHasNextPage(), pageInfo.getNextPage(), getC2bAgentWithdrawalOrderResult(pageInfo.getList()));
    }

    /**
     * 小vip酒店提现订单查询
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    public PageResult<HotelWithdrawalOrderResult> myMiniVipHotelList(AccountInfo loginUser, WithdrawalOrderParam param) {
        return myC2bHotelList(loginUser, param);
    }


    /**
     * 小vip运营商提现订单查询
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    public PageResult<AgentWithdrawalOrderResult> myMiniVipOperatorList(AccountInfo loginUser, WithdrawalOrderParam param) {
        Map<String, Object> map = myListMap(param);
        map.put("operatorName", param.getOperatorName());
        map.put("operatorPhone", param.getOperatorPhone());
        if (!AccountInfoTypeEnum.Administrator.value().equals(loginUser.getType())) {
            map.put("operatorId", AccountUtil.getOperationUserId(loginUser));
            map.put("accountTypes", Lists.newArrayList(loginUser.getType()));
        } else {
            map.put("accountTypes", Lists.newArrayList(20, 21, 22));
        }
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<HotelWithdrawalOrder> orders = baseMapper.myC2bAgentList(map);
        PageInfo<HotelWithdrawalOrder> pageInfo = PageInfo.of(orders);
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getPages(), pageInfo.isHasNextPage(), pageInfo.getNextPage(), getC2bAgentWithdrawalOrderResult(pageInfo.getList()));
    }

    /**
     * 组装提现订单列表查询条件
     *
     * @param param
     * @return
     */
    public Map<String, Object> myListMap(WithdrawalOrderParam param) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("status", param.getStatus());
        map.put("orderType", param.getOrderType());
        if ((null == param.getStartTime() && null != param.getEndTime())
                || (null == param.getEndTime() && null != param.getStartTime())) {
            throw new ServiceException("开始时间结束时间必须同时传");
        }
        if (null != param.getStartTime() && null != param.getEndTime()) {
            map.put("startTime", new Date(param.getStartTime()));
            map.put("endTime", new Date(param.getEndTime()));
        }
        return map;
    }

    /**
     * 更新提现订单状态
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean myUpdate(AccountInfo loginUser, FinanceOrderUpdateParam param) {
        Arguments.isTrue(AccountType.Administrator != loginUser.getType(), "当前用户无权访问");
        HotelWithdrawalOrder order = baseMapper.selectOne(new QueryWrapper<HotelWithdrawalOrder>()
                .eq(HotelWithdrawalOrder.ORDER_NO, param.getOrderNo())
                .eq(HotelWithdrawalOrder.ORDER_TYPE, param.getType()));
        Arguments.beanIsNull(order, "该订单不存在");
        Date date = new Date();
        order.setOperatorId(loginUser.getId());
        order.setGmtModified(date);
        //审核通过
        if (HotelWithdrawalOrder.Status.PASS.value().equals(param.getStatus())) {
            if (!HotelWithdrawalOrder.Status.WAIT.value().equals(order.getStatus())) {
                log.info("该订单非申请结算中状态{}", order);
                throw new ServiceException("该订单非申请结算中状态");
            }
            order.setStatus(HotelWithdrawalOrder.Status.PASS.value());
            order.setAuditId(loginUser.getId());
            order.setAuditTime(date);
        }
        //打款成功
        if (HotelWithdrawalOrder.Status.SUCCESS.value().equals(param.getStatus())) {
            if (!HotelWithdrawalOrder.Status.TRANSFER.value().equals(order.getStatus())) {
                log.info("该订单非转账中状态{}", order);
                throw new ServiceException("该订单非转账中状态");
            }
            order.setStatus(HotelWithdrawalOrder.Status.SUCCESS.value());
            order.setPayTime(date);
        }
        //打款失败
        if (HotelWithdrawalOrder.Status.FAIL.value().equals(param.getStatus())) {
            if (!HotelWithdrawalOrder.Status.TRANSFER.value().equals(order.getStatus())) {
                log.info("该订单非转账中状态{}", order);
                throw new ServiceException("该订单非转账中状态");
            }
            order.setStatus(HotelWithdrawalOrder.Status.FAIL.value());
            //余额回退
            remainAdd(order, param);
        }
        //拒绝
        if (HotelWithdrawalOrder.Status.REFUND.value().equals(param.getStatus())) {
            if (!HotelWithdrawalOrder.Status.WAIT.value().equals(order.getStatus())) {
                log.info("该订单非申请结算中状态{}", order);
                throw new ServiceException("该订单非申请结算中状态");
            }
            order.setStatus(HotelWithdrawalOrder.Status.REFUND.value());
            order.setAuditId(loginUser.getId());
            order.setAuditTime(date);
            //余额回退
            remainAdd(order, param);
        }
        order.setRemark(param.getRemark());
        if (baseMapper.updateById(order) != 1) {
            throw new ServiceException("更新订单状态失败");
        }
        return true;
    }

    /**
     * 批量修改提现订单状态为审核通过
     *
     * @param loginUser
     * @param param
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean myUpdateMore(AccountInfo loginUser, FinanceOrderUpdateMoreParam param) {
        Arguments.isTrue(AccountType.Administrator != loginUser.getType(), "当前用户无权访问");
        List<String> orderNos = Splitters.splitToString(param.getOrderNo(), Splitters.COMMA);
        Date date = new Date();
        for (String orderNo : orderNos) {
            HotelWithdrawalOrder order = getHotelWithdrawalOrder(orderNo, param.getType());
            if (!HotelWithdrawalOrder.Status.WAIT.value().equals(order.getStatus())) {
                log.info("该订单非申请结算中状态{}", order.getOrderNo());
                throw new ServiceException("该订单非申请结算中状态");
            }
            order.setOperatorId(loginUser.getId());
            order.setStatus(HotelWithdrawalOrder.Status.PASS.value());
            order.setAuditId(loginUser.getId());
            order.setAuditTime(date);
            order.setGmtModified(date);
            Arguments.isFalse(baseMapper.updateById(order) == 1, "更新订单状态失败");
        }
        return true;
    }

    /**
     * 余额回退
     */
    private void remainAdd(HotelWithdrawalOrder order, FinanceOrderUpdateParam param) {
        //营业提现
        if (HotelWithdrawalOrder.OrderType.ORDER.value().equals(order.getOrderType())) {
            hotelAccountOverviewService.addAccount(order.getOrderNo(), param.getRemark());
        }
        //床垫分成提现
        if (HotelWithdrawalOrder.OrderType.MATTRESS.value().equals(order.getOrderType())) {
            overviewService.add(order.getOrderNo(), param.getRemark());
        }
        //vip佣金提现
        if (HotelWithdrawalOrder.OrderType.VIP.value().equals(order.getOrderType())) {
            vipCommissionOverviewService.remainAdd(order.getOrderNo(), param.getRemark());
        }
        //小vip佣金提现
        if (HotelWithdrawalOrder.OrderType.MINI_VIP.value().equals(order.getOrderType())) {
            miniVipCommissionBillService.remainAdd(order.getOrderNo(), param.getRemark());
        }
    }


    @Override
    public CommonResult<CommonPage<HotelWithdrawalOrderResult>> adminAppList(QueryWithdrawalOrderParam param, AccountInfo accountInfo) {

        CommonPage<HotelWithdrawalOrderResult> resultCommonPage = new CommonPage<>();

        if (AccountType.Administrator != accountInfo.getType() && AccountType.HotelManager != accountInfo.getType()) {
            return CommonResult.failed("你无权查看");
        }

        PageResult<HotelWithdrawalOrderResult> pageResult = myC2bHotelList(accountInfo, MyBeanUtils.convert(param, WithdrawalOrderParam.class));
        if (null != pageResult && !CollectionUtils.isEmpty(pageResult.getList())) {
            //将得到的分页信息放入自己的分页中
            resultCommonPage.setList(pageResult.getList());
            resultCommonPage.setPageNum(param.getPageNum());
            resultCommonPage.setPageSize(param.getPageSize());
            resultCommonPage.setTotal(pageResult.getTotal());
            resultCommonPage.setTotalPage(Long.valueOf(pageResult.getPageCount()));
        }
        resultCommonPage.getList().forEach(withdrawalOrderResult -> {
            withdrawalOrderResult.setStatusCn(HotelWithdrawalOrder.Status.getDesc(withdrawalOrderResult.getStatus()));
        });
        return CommonResult.success(resultCommonPage);
    }

    @Override
    public CommonResult<CommonPage<HotelWithdrawalOrderResult>> adminAppVipHotelList(QueryWithdrawalOrderParam param, AccountInfo loginUser) {
        return adminAppList(param, loginUser);
    }

    @Override
    public CommonResult<CommonPage<AgentWithdrawalOrderResult>> adminAppC2bAgentList(QueryWithdrawalOrderParam param, AccountInfo loginUser) {

        CommonPage<AgentWithdrawalOrderResult> withdrawalOrderResultCommonPage = new CommonPage<>();

        //直接调用查询（web）
        PageResult<AgentWithdrawalOrderResult> pageResult = myC2bAgentList(loginUser, MyBeanUtils.convert(param, WithdrawalOrderParam.class));
        if (null != pageResult && !CollectionUtils.isEmpty(pageResult.getList())) {
            withdrawalOrderResultCommonPage.setList(pageResult.getList());
            withdrawalOrderResultCommonPage.setPageNum(param.getPageNum());
            withdrawalOrderResultCommonPage.setPageSize(param.getPageSize());
            withdrawalOrderResultCommonPage.setTotal(pageResult.getTotal());
            withdrawalOrderResultCommonPage.setTotalPage(Long.valueOf(pageResult.getPageCount()));
        }

        withdrawalOrderResultCommonPage.getList().forEach(withdrawalOrderResult -> {
            withdrawalOrderResult.setStatusCn(HotelWithdrawalOrder.Status.getDesc(withdrawalOrderResult.getStatus()));
        });
        return CommonResult.success(withdrawalOrderResultCommonPage);
    }

    @Override
    public CommonResult<CommonPage<AgentWithdrawalOrderResult>> adminAppVipAgentList(QueryWithdrawalOrderParam param, AccountInfo loginUser) {

        CommonPage<AgentWithdrawalOrderResult> withdrawalOrderResultCommonPage = new CommonPage<>();

        PageResult<AgentWithdrawalOrderResult> pageResult = myVipOperatorList(loginUser, MyBeanUtils.convert(param, WithdrawalOrderParam.class));
        if (null != pageResult && !CollectionUtils.isEmpty(pageResult.getList())) {
            withdrawalOrderResultCommonPage.setList(pageResult.getList());
            withdrawalOrderResultCommonPage.setPageNum(param.getPageNum());
            withdrawalOrderResultCommonPage.setPageSize(param.getPageSize());
            withdrawalOrderResultCommonPage.setTotal(pageResult.getTotal());
            withdrawalOrderResultCommonPage.setTotalPage(Long.valueOf(pageResult.getPageCount()));
        }

        withdrawalOrderResultCommonPage.getList().forEach(withdrawalOrderResult -> {
            withdrawalOrderResult.setStatusCn(HotelWithdrawalOrder.Status.getDesc(withdrawalOrderResult.getStatus()));
        });
        return CommonResult.success(withdrawalOrderResultCommonPage);
    }

    @Override
    public List<AppFinanceStatusDTO> getStatusList(AccountInfo accountInfo) {

        List<AppFinanceStatusDTO> appFinanceStatusDTOList = Lists.newArrayList();

        List<FinanceStatusEnum> h = Arrays.asList(FinanceStatusEnum.values());

        h.forEach(financeStatusEnum -> {
            AppFinanceStatusDTO financeStatusDTO = new AppFinanceStatusDTO();
            financeStatusDTO.setType(financeStatusEnum.getCode());
            financeStatusDTO.setValue(financeStatusEnum.getMsg());
            appFinanceStatusDTOList.add(financeStatusDTO);
        });

        return appFinanceStatusDTOList;
    }

    private List<HotelWithdrawalOrderResult> getC2bHotelWithdrawalOrderResult(List<HotelWithdrawalOrder> orders) {
        List<HotelWithdrawalOrderResult> lists = Lists.newArrayList();
        if (orders == null || orders.size() == 0) {
            return lists;
        }
        for (HotelWithdrawalOrder order : orders) {
            HotelWithdrawalOrderResult c2bHotelWithdrawalOrderResult = ObjectConvertUtil.convertObject(order, HotelWithdrawalOrderResult.class);
            if (null == c2bHotelWithdrawalOrderResult) {
                continue;
            }
            try {
                c2bHotelWithdrawalOrderResult.setLastTime(getLastTime(order));
                HotelInfo hotelInfo = hotelInfoService.searchHotelByOperator(order.getAccountId());
                if (hotelInfo != null) {
                    c2bHotelWithdrawalOrderResult.setHotelName(hotelInfo.getName());
                    c2bHotelWithdrawalOrderResult.setName(hotelInfo.getContactName());
                    c2bHotelWithdrawalOrderResult.setHotelPhone(hotelInfo.getPhone());
                    c2bHotelWithdrawalOrderResult.setStatusCn(HotelWithdrawalOrder.Status.getDesc(order.getStatus()));
                    String payAccounts = hotelInfo.getPayAccounts();
                    if (Arguments.strNotNull(payAccounts)) {
                        JSONObject jsonObject = JSONObject.parseObject(payAccounts).getJSONObject("pay_accounts");
                        if (null != jsonObject) {
                            NewPayAmountDTO newPayAmountDTO = jsonObject.toJavaObject(NewPayAmountDTO.class);
                            if (null != newPayAmountDTO) {
                                c2bHotelWithdrawalOrderResult.setBankCard(newPayAmountDTO.getBankCard());
                                c2bHotelWithdrawalOrderResult.setBankName(newPayAmountDTO.getBankName());
                                c2bHotelWithdrawalOrderResult.setBranchBankName(newPayAmountDTO.getBranchBankName());
                            }
                        }
                    }
                }
                lists.add(c2bHotelWithdrawalOrderResult);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return lists;
    }

    private List<AgentWithdrawalOrderResult> getC2bAgentWithdrawalOrderResult(List<HotelWithdrawalOrder> orders) {
        List<AgentWithdrawalOrderResult> lists = Lists.newArrayList();
        if (orders == null || orders.size() == 0) {
            return lists;
        }
        for (HotelWithdrawalOrder order : orders) {
            AgentWithdrawalOrderResult c2bAgentWithdrawalOrderResult = ObjectConvertUtil.convertObject(order, AgentWithdrawalOrderResult.class);
            if (null == c2bAgentWithdrawalOrderResult) {
                continue;
            }

            c2bAgentWithdrawalOrderResult.setLastTime(getLastTime(order));
            AccountInfo accountInfo = accountInfoService.selectByPrimaryKey(order.getAccountId());
            c2bAgentWithdrawalOrderResult.setAgentName(accountInfo.getUsername());
            c2bAgentWithdrawalOrderResult.setAgentType(AccountInfoTypeEnum.getDesc(accountInfo.getType()));
            c2bAgentWithdrawalOrderResult.setPhone(accountInfo.getPhone());
            c2bAgentWithdrawalOrderResult.setStatusCn(HotelWithdrawalOrder.Status.getDesc(order.getStatus()));
            try {
                if (null != accountInfo.getExtraInfo() && accountInfo.getExtraInfo().contains("pay_accounts")) {
                    AccountPayAccountDTO payAccountDTO = JSONUtil.toBean(accountInfo.getExtraInfo(), AccountPayAccountDTO.class);
                    c2bAgentWithdrawalOrderResult.setBankName(payAccountDTO.getPayAccounts().getBankName());
                    c2bAgentWithdrawalOrderResult.setBankCard(payAccountDTO.getPayAccounts().getBankCard());
                    c2bAgentWithdrawalOrderResult.setBranchBankName(payAccountDTO.getPayAccounts().getBranchBankName());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            lists.add(c2bAgentWithdrawalOrderResult);
        }
        return lists;
    }


    private Date getLastTime(HotelWithdrawalOrder e) {
        HotelWithdrawalOrder hotelWithdrawalOrder = baseMapper.selectOne(new QueryWrapper<HotelWithdrawalOrder>()
                .eq(HotelWithdrawalOrder.STATUS, HotelWithdrawalOrder.Status.PASS.value())
                .eq(HotelWithdrawalOrder.ACCOUNT_ID, e.getAccountId())
                .eq(HotelWithdrawalOrder.ACCOUNT_TYPE, e.getAccountType())
                .lt(HotelWithdrawalOrder.GMT_CREATE, e.getGmtCreate())
                .orderByDesc(HotelWithdrawalOrder.GMT_CREATE)
                .last("limit 1"));
        if (null == hotelWithdrawalOrder) {
            return null;
        }
        return hotelWithdrawalOrder.getGmtCreate();
    }

    private Map<Integer, HotelInfo> getHotelInfoMap(List<HotelWithdrawalOrder> orders) {
        List<Integer> hotelIds = Lists.transform(orders, HotelWithdrawalOrder::getHotelId);
        List<HotelInfo> hotelInfos = hotelInfoService.selectByIds(hotelIds);
        return Maps.uniqueIndex(hotelInfos, HotelInfo::getId);
    }

    /**
     * #####################################################################################################
     * 3.4.vip修改
     * #####################################################################################################
     *
     */

    /**
     * 申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean withdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        Arguments.intEqualZero(param.getAmount(), "提现金额不能为0");
        Arguments.intLtZero(param.getAmount(), "提现金额有误");
        if (!smsService.verifySmsForSignup(param.getPhone(), param.getCode())) {
            throw new ServiceException("验证码输入有误");
        }
        //判断当前用户是否可以提现
        checkWithdrawalV2(loginUser, param.getType());
        Integer operationUserId = AccountUtil.getOperationUserId(loginUser);
        String orderNo = IdWorkerUtil.nextStrId();
        HotelWithdrawalOrder order = new HotelWithdrawalOrder();
        order.setOrderNo(orderNo);
        order.setOrderType(param.getType());
        order.setStatus(HotelWithdrawalOrder.Status.WAIT.value());
        order.setRemark(HotelWithdrawalOrder.Remark.APPLICATION.desc());
        order.setAmount(param.getAmount());
        order.setDeleteFlag(0);
        Date date = new Date();
        order.setGmtCreate(date);
        order.setGmtModified(date);
        order.setAccountId(operationUserId);
        order.setAccountType(loginUser.getType());
        //酒店账户提现
        if (AccountType.HotelManager == loginUser.getType()) {
            //通过登录用户id查询酒店
            HotelInfo hotelInfo = hotelInfoService.getHotelInfoAccountHotelInfo(loginUser);
            Arguments.strNotEqualStr(param.getPhone(), hotelInfo.getPhone(), "操作非法，非酒店所属人的手机号");
            //营业提现
            if (HotelWithdrawalOrder.OrderType.ORDER.value().equals(param.getType())) {
                hotelAccountOverviewService.descAccount(operationUserId, param.getAmount(), orderNo, loginUser.getType());
            }
            //床垫分成提现
            if (HotelWithdrawalOrder.OrderType.MATTRESS.value().equals(param.getType())) {
                overviewService.desc(hotelInfo.getId(), param.getAmount(), orderNo);
            }
            //vip佣金提现
            if (HotelWithdrawalOrder.OrderType.VIP.value().equals(param.getType())) {
                vipCommissionBillService.desc(operationUserId, param.getAmount(), orderNo);
            }
            order.setPhone(hotelInfo.getPhone());
            order.setBankInfo(hotelInfo.getPayAccounts());
        }
        //运营商服务商卡商
        if (AccountType.OperateMerchant == loginUser.getType()
                || AccountType.ServiceMerchant == loginUser.getType()
                || AccountType.VipCardMerchant == loginUser.getType()) {
            AccountInfo accountInfo = accountInfoService.getById(operationUserId);
            //vip佣金提现
            if (HotelWithdrawalOrder.OrderType.VIP.value().equals(param.getType())) {
                vipCommissionBillService.desc(operationUserId, param.getAmount(), orderNo);
            }
            order.setPhone(accountInfo.getPhone());
            order.setBankInfo(accountInfo.getExtraInfo());
        }
        if (baseMapper.insert(order) != 1) {
            throw new ServiceException("生成提现订单异常");
        }
        return true;
    }

    /**
     * c2b酒店申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean c2bHotelWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        HotelWithdrawalOrder order = checkAndGetHotelWithdrawalOrder(loginUser, param);
        //通过登录用户id查询酒店
        HotelInfo hotelInfo = hotelInfoService.getHotelInfoAccountHotelInfo(loginUser);
        Arguments.strNotEqualStr(param.getPhone(), hotelInfo.getPhone(), "操作非法，非酒店所属人的手机号");
        //酒店提现
        hotelAccountOverviewService.descAccount(hotelInfo.getOperatorId(), param.getAmount(), order.getOrderNo(), loginUser.getType());
        order.setPhone(hotelInfo.getPhone());
        order.setBankInfo(hotelInfo.getPayAccounts());
        if (baseMapper.insert(order) != 1) {
            throw new ServiceException("生成提现订单异常");
        }
        return true;
    }

    /**
     * c2b代理申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean c2bAgentWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        Integer operationUserId = AccountUtil.getOperationUserId(loginUser);
        HotelWithdrawalOrder order = checkAndGetHotelWithdrawalOrder(loginUser, param);
        //通过登录用户id查询酒店
        Arguments.strNotEqualStr(param.getPhone(), loginUser.getPhone(), "操作非法，非所属人的手机号");
        //代理提现
        hotelAccountOverviewService.descAccount(operationUserId, param.getAmount(), order.getOrderNo(), loginUser.getType());
        order.setPhone(loginUser.getPhone());
        order.setBankInfo(loginUser.getExtraInfo());
        Arguments.isTrue(baseMapper.insert(order) != 1, "生成提现订单异常");
        return true;
    }

    /**
     * 床垫酒店申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean mattressHotelWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        HotelInfo hotelInfo = hotelInfoService.getHotelInfoAccountHotelInfo(loginUser);
        HotelWithdrawalOrder order = checkAndGetHotelWithdrawalOrder(loginUser, param);
        Arguments.strNotEqualStr(param.getPhone(), loginUser.getPhone(), "操作非法，非所属人的手机号");
        //床垫分成提现
        overviewService.desc(hotelInfo.getOperatorId(), param.getAmount(), order.getOrderNo());
        order.setPhone(hotelInfo.getPhone());
        order.setBankInfo(hotelInfo.getPayAccounts());
        Arguments.isTrue(baseMapper.insert(order) != 1, "生成提现订单异常");
        return true;
    }

    /**
     * 床垫代理申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean mattressAgentWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        Integer operationUserId = AccountUtil.getOperationUserId(loginUser);
        HotelWithdrawalOrder order = checkAndGetHotelWithdrawalOrder(loginUser, param);
        Arguments.strNotEqualStr(param.getPhone(), loginUser.getPhone(), "操作非法，非所属人的手机号");
        //床垫分成提现
        overviewService.desc(operationUserId, param.getAmount(), order.getOrderNo());
        order.setPhone(loginUser.getPhone());
        order.setBankInfo(loginUser.getExtraInfo());
        Arguments.isTrue(baseMapper.insert(order) != 1, "生成提现订单异常");
        return true;
    }

    /**
     * vip酒店申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean vipHotelWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        vipWithdrawal(loginUser, param, 1);
        return true;
    }

    /**
     * vip运营商申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean vipOperatorWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        vipWithdrawal(loginUser, param, 2);
        return true;
    }

    /**
     * vip提现
     *
     * @param loginUser
     * @param param
     * @param type      1 酒店，2运营商
     */
    private void vipWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param, Integer type) {
        HotelWithdrawalOrder order = checkAndGetHotelWithdrawalOrder(loginUser, param);
        if (1 == type) {
            HotelInfo hotelInfo = hotelInfoService.getHotelInfoAccountHotelInfo(loginUser);
            Arguments.strNotEqualStr(param.getPhone(), hotelInfo.getPhone(), "操作非法，非所属人的手机号");
            //vip佣金提现
            vipCommissionBillService.desc(hotelInfo.getOperatorId(), param.getAmount(), order.getOrderNo());
            order.setPhone(hotelInfo.getPhone());
            order.setBankInfo(hotelInfo.getPayAccounts());
        } else {
            Arguments.strNotEqualStr(param.getPhone(), loginUser.getPhone(), "操作非法，非所属人的手机号");
            //vip佣金提现
            vipCommissionBillService.desc(AccountUtil.getOperationUserId(loginUser), param.getAmount(), order.getOrderNo());
            order.setPhone(loginUser.getPhone());
            order.setBankInfo(loginUser.getExtraInfo());
        }
        Arguments.isTrue(baseMapper.insert(order) != 1, "生成提现订单异常");
    }

    /**
     * 小vip酒店申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean miniVipHotelWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        miniVipWithdrawal(loginUser, param, 1);
        return true;
    }

    /**
     * 小vip运营商申请提现
     *
     * @param loginUser 申请人
     * @param param     参数
     * @return
     */
    @Override
    public boolean miniVipOperatorWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param) {
        miniVipWithdrawal(loginUser, param, 2);
        return true;
    }

    /**
     * 小vip提现
     *
     * @param loginUser
     * @param param
     * @param type      1 酒店，2运营商
     */
    private void miniVipWithdrawal(AccountInfo loginUser, FinanceWithdrawalParam param, Integer type) {
        HotelWithdrawalOrder order = checkAndGetHotelWithdrawalOrder(loginUser, param);
        if (1 == type) {
            HotelInfo hotelInfo = hotelInfoService.getHotelInfoAccountHotelInfo(loginUser);
            Arguments.strNotEqualStr(param.getPhone(), hotelInfo.getPhone(), "操作非法，非所属人的手机号");
            miniVipCommissionBillService.remainDesc(hotelInfo.getOperatorId(), param.getAmount(), order.getOrderNo());
            order.setPhone(hotelInfo.getPhone());
            order.setBankInfo(hotelInfo.getPayAccounts());
        } else {
            Arguments.strNotEqualStr(param.getPhone(), loginUser.getPhone(), "操作非法，非所属人的手机号");
            miniVipCommissionBillService.remainDesc(AccountUtil.getOperationUserId(loginUser), param.getAmount(), order.getOrderNo());
            order.setPhone(loginUser.getPhone());
            order.setBankInfo(loginUser.getExtraInfo());
        }
        Arguments.isTrue(baseMapper.insert(order) != 1, "生成提现订单异常");
    }

    /**
     * 校验并且返回提现订单对象
     *
     * @return
     */
    private HotelWithdrawalOrder checkAndGetHotelWithdrawalOrder(AccountInfo loginUser, FinanceWithdrawalParam param) {
        Arguments.intEqualZero(param.getAmount(), "提现金额不能为0");
        Arguments.intLtZero(param.getAmount(), "提现金额有误");
        if (!smsService.verifySmsForSignup(param.getPhone(), param.getCode())) {
            throw new ServiceException("验证码输入有误");
        }
        Integer operationUserId = AccountUtil.getOperationUserId(loginUser);
        //判断当前用户是否可以提现
        checkWithdrawalV2(loginUser, param.getType());
        String orderNo = IdWorkerUtil.nextStrId();
        HotelWithdrawalOrder order = new HotelWithdrawalOrder();
        order.setOrderNo(orderNo);
        order.setOrderType(param.getType());
        order.setStatus(HotelWithdrawalOrder.Status.WAIT.value());
        order.setRemark(HotelWithdrawalOrder.Remark.APPLICATION.desc());
        order.setAmount(param.getAmount());
        order.setDeleteFlag(0);
        Date date = new Date();
        order.setGmtCreate(date);
        order.setGmtModified(date);
        order.setAccountId(operationUserId);
        order.setAccountType(loginUser.getType());
        return order;
    }

    /**
     * 获取C2B分佣账户余额
     *
     * @param loginUser
     * @return
     */
    @Override
    public Map<String, Object> c2bRemain(AccountInfo loginUser) {
        HotelAccountOverview overview = hotelAccountOverviewService.selectByAccountId(AccountUtil.getOperationUserId(loginUser), loginUser.getType());
        return ImmutableMap.of("remain", overview.getRemainAmount(), "phone", null==loginUser.getPhone()?"":loginUser.getPhone());
    }

    /**
     * 获取vip分佣账户余额
     *
     * @param loginUser
     * @return
     */
    @Override
    public Map<String, Object> vipRemain(AccountInfo loginUser) {
        VipCommissionOverview overview = vipCommissionOverviewService.selectByAccountId(AccountUtil.getOperationUserId(loginUser));
        return ImmutableMap.of("remain", overview.getRemainAmount(),
                "phone", loginUser.getPhone(),
                "totalInAmount", overview.getTotalInAmount());
    }

    /**
     * 获取小vip分佣账户余额
     *
     * @param loginUser
     * @return
     */
    @Override
    public Map<String, Object> miniVipRemain(AccountInfo loginUser) {
        MiniVipCommissionOverview overview = miniVipCommissionOverviewService.selectByAccountId(AccountUtil.getOperationUserId(loginUser));
        return ImmutableMap.of("remain", overview.getRemainAmount(),
                "phone", loginUser.getPhone(),
                "totalInAmount", overview.getTotalInAmount());
    }

    /**
     * 获取收支账户信息
     *
     * @param loginUser
     * @return
     */
    @Override
    public FinanceBindParam getBankInfo(AccountInfo loginUser) {
        if (AccountType.HotelManager == loginUser.getType()) {
            HotelInfo accountHotelInfo = hotelInfoService.getHotelInfoAccountHotelInfo(loginUser);
            String payAccounts = accountHotelInfo.getPayAccounts();
            return JsonUtils.getJsonToBean("pay_accounts", payAccounts, FinanceBindParam.class);
        }
        return JsonUtils.getJsonToBean("pay_accounts", loginUser.getExtraInfo(), FinanceBindParam.class);
    }

    /**
     * 绑定或修改银行账户
     *
     * @param loginUser
     * @param financeBindParam
     * @return
     */
    @Override
    public boolean bind(AccountInfo loginUser, FinanceBindParam financeBindParam) {
        if (AccountType.HotelManager == loginUser.getType()) {
            //查询当前登录的酒店账户对应的酒店
            HotelInfo hotelInfo = hotelInfoService.getHotelInfoAccountHotelInfo(loginUser);
            hotelInfo.setPayAccounts(JsonUtils.addJsonBean("pay_accounts", financeBindParam));
            Arguments.isTrue(!hotelInfoService.updateById(hotelInfo), "绑定酒店银行账户信息失败");
        } else {
            //查询当前登录账户
            AccountInfo accountInfo = accountInfoService.getById(AccountUtil.getOperationUserId(loginUser));
            Arguments.beanIsNull(accountInfo, "当前登录账户不存在");
            if (null == accountInfo.getExtraInfo()) {
                accountInfo.setExtraInfo(JsonUtils.addJsonBean("pay_accounts", financeBindParam));
            } else {
                accountInfo.setExtraInfo(JsonUtils.addJsonBean("pay_accounts", financeBindParam, accountInfo.getExtraInfo()));
            }
            Arguments.isTrue(!accountInfoService.updateById(accountInfo), "绑定银行账户信息失败");
        }
        return true;
    }

    /**
     * 总公司绑定酒店银行账户
     *
     * @param financeBindParam
     * @return
     */
    @Override
    public boolean bindHotel(FinanceBindHotelParam financeBindParam) {
        //查询当前登录的酒店账户对应的酒店
        HotelInfo hotelInfo = hotelInfoService.getById(financeBindParam.getHotelId());
        FinanceBindParam param = ObjectConvertUtil.convertObject(financeBindParam, FinanceBindParam.class);
        hotelInfo.setPayAccounts(JsonUtils.addJsonBean("pay_accounts", param));
        Arguments.isTrue(!hotelInfoService.updateById(hotelInfo), "绑定酒店银行账户信息失败");
        return true;
    }

    /**
     * 酒店提现订单导出
     *
     * @param param
     * @return
     */
    @Override
    public List<WithdrawalOrderDownloadResult> hotelOrderDownload(WithdrawalOrderDownloadParam param) {
        List<DownloadResult> result = getHotelOrderDownloadResult(orderDownloadList(param));
        return ObjectConvertUtil.convertList(result, WithdrawalOrderDownloadResult.class);
    }

    /**
     * 代理提现订单导出
     *
     * @param param
     * @return
     */
    @Override
    public List<WithdrawalOrderAgentDownloadResult> agentOrderDownload(WithdrawalOrderDownloadParam param) {
        List<DownloadResult> result = getHotelOrderDownloadResult(orderDownloadList(param));
        return ObjectConvertUtil.convertList(result, WithdrawalOrderAgentDownloadResult.class);
    }

    /**
     * 提现订单查询
     *
     * @param param
     * @return
     */
    public List<HotelWithdrawalOrder> orderDownloadList(WithdrawalOrderDownloadParam param) {
        Arguments.isTrue((null != param.getStartTime() && null == param.getEndTime()) || (null == param.getStartTime() && null != param.getEndTime()), "时间必传");
        Map<String, Object> map = Maps.newHashMap();
        if (null != param.getStartTime() && null != param.getEndTime()) {
            map.put("startTime", new Date(param.getStartTime()));
            map.put("endTime", new Date(param.getEndTime()));
        }
        map.put("orderType", param.getOrderType());
        map.put("accountTypes", Splitters.splitToInteger(param.getAccountType(), Splitters.COMMA));
        map.put("statusList", Splitters.splitToInteger(param.getStatus(), Splitters.COMMA));
        return baseMapper.selectOrderDownload(map);
    }

    private List<DownloadResult> getHotelOrderDownloadResult(List<HotelWithdrawalOrder> hotelWithdrawalOrders) {
        if (null == hotelWithdrawalOrders || hotelWithdrawalOrders.size() == 0) {
            return Lists.newArrayList();
        }
        List<DownloadResult> downloadResults = Lists.newArrayList();
        for (HotelWithdrawalOrder hotelWithdrawalOrder : hotelWithdrawalOrders) {
            try {
                DownloadResult downloadResult = ObjectConvertUtil.convertObject(hotelWithdrawalOrder, DownloadResult.class);
                if (null != downloadResult) {
                    downloadResult.setAmount(FormatUtils.fenToYuan(hotelWithdrawalOrder.getAmount()));
                    downloadResult.setStatus(HotelWithdrawalOrder.Status.getDesc(hotelWithdrawalOrder.getStatus()));
                    //通过账户id查询账户信息
                    AccountInfo accountInfo = accountInfoService.getById(hotelWithdrawalOrder.getAccountId());
                    //酒店的话拿酒店的手机号以及用户
                    if (AccountType.HotelManager == accountInfo.getType()) {
                        HotelInfo hotelInfo = hotelInfoService.selectHotelInfoByOperatorId(accountInfo.getId());
                        downloadResult.setHotelName(hotelInfo.getName());
                        downloadResult.setName(hotelInfo.getContactName());
                        downloadResult.setPhone(hotelInfo.getPhone());
                        if (null != hotelInfo.getPayAccounts()) {
                            AccountPayAccountDTO payAccountDTO = JSONUtil.toBean(hotelInfo.getPayAccounts(), AccountPayAccountDTO.class);
                            downloadResult.setBankName(payAccountDTO.getPayAccounts().getBankName());
                            downloadResult.setBankCard(payAccountDTO.getPayAccounts().getBankCard());
                            downloadResult.setUsername(payAccountDTO.getPayAccounts().getUserName());
                        }
                    } else {
                        downloadResult.setPhone(accountInfo.getPhone());
                        downloadResult.setAgentName(accountInfo.getUsername());
                        downloadResult.setAgentType(AccountInfoTypeEnum.getDesc(accountInfo.getType()));
                        if (null != accountInfo.getExtraInfo() && accountInfo.getExtraInfo().contains("pay_accounts")) {
                            AccountPayAccountDTO payAccountDTO = JSONUtil.toBean(accountInfo.getExtraInfo(), AccountPayAccountDTO.class);
                            downloadResult.setBankName(payAccountDTO.getPayAccounts().getBankName());
                            downloadResult.setBankCard(payAccountDTO.getPayAccounts().getBankCard());
                            downloadResult.setUsername(payAccountDTO.getPayAccounts().getUserName());
                        }
                    }
                    downloadResults.add(downloadResult);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return downloadResults;
    }

    /**
     * 判断当前用户是否可以提现
     *
     * @param loginAccount 当前登录账户
     * @param type         0营业提现，1床垫分成提现，2vip佣金提现，3小vip佣金提现
     * @return
     */
    @Override
    public Boolean checkWithdrawal(AccountInfo loginAccount, Integer type) {
        return checkWithdrawalV2(loginAccount, type);
    }

    /**
     * 判断当前用户是否可以提现
     *
     * @param loginAccount 当前登录账户
     * @param type         0营业提现，1床垫分成提现，2vip佣金提现，3小vip提现
     * @return
     */
    public Boolean checkWithdrawalV2(AccountInfo loginAccount, Integer type) {
        Integer operationUserId = AccountUtil.getOperationUserId(loginAccount);
        if (AccountType.HotelManager == loginAccount.getType()) {
            //通过酒店所有人获取酒店
            HotelInfo hotelInfo = hotelInfoService.getHotelInfoAccountHotelInfo(loginAccount);
            Arguments.strIsNull(hotelInfo.getPayAccounts(), "您还未绑卡请先去绑卡");
            //检查提现订单
            checkWithdrawalForOrder(operationUserId, type, AccountInfoTypeEnum.HotelManager.value());
        } else {
            AccountInfo accountInfo = accountInfoService.getById(operationUserId);
            Arguments.strIsNull(accountInfo.getExtraInfo(), "您还未绑卡请先去绑卡");
            if (!accountInfo.getExtraInfo().contains("pay_accounts")) {
                throw new ServiceException("您还未绑卡请先去绑卡");
            }
            //检查提现订单
            checkWithdrawalForOrder(operationUserId, type, accountInfo.getType());
        }
        return true;
    }

    /**
     * 检查提现订单
     *
     * @param operationUserId
     * @param orderType       0营业提现，1床垫分成提现，2vip佣金提现，3小vip提现
     * @param accountType     账户类型，和accountInfo表中的类型一样
     */
    private void checkWithdrawalForOrder(Integer operationUserId, Integer orderType, Integer accountType) {
        QueryWrapper<HotelWithdrawalOrder> wrapper = new QueryWrapper<>();
        wrapper.eq(HotelWithdrawalOrder.ORDER_TYPE, orderType)
                .in(HotelWithdrawalOrder.STATUS, HotelWithdrawalOrder.Status.WAIT.value())
                .eq(HotelWithdrawalOrder.ACCOUNT_ID, operationUserId)
                .eq(HotelWithdrawalOrder.ACCOUNT_TYPE, accountType);
        List<HotelWithdrawalOrder> orders = baseMapper.selectList(wrapper);
        Arguments.listNotNull(orders, "您有正在处理的提现订单");
        //查询今日提现的订单
        List<HotelWithdrawalOrder> hotelWithdrawalOrders = baseMapper.selectTodayOrder(operationUserId, accountType, HotelWithdrawalOrder.Status.PASS.value(), orderType);
        Arguments.listNotNull(hotelWithdrawalOrders, "一天内只能提现一次");
        //查询本周提现成功的订单
//        List<HotelWithdrawalOrder> hotelWithdrawalOrders = baseMapper.selectThisWeek(operationUserId, accountType, HotelWithdrawalOrder.Status.PASS.value(), orderType);
//        Arguments.listNotNull(hotelWithdrawalOrders, "一周内只能提现一次");
    }

    /**
     * 通过订单号和订单类型查询
     *
     * @param orderNo
     * @param orderType
     * @return
     */
    private HotelWithdrawalOrder getHotelWithdrawalOrder(String orderNo, Integer orderType) {
        HotelWithdrawalOrder order = baseMapper.selectOne(new QueryWrapper<HotelWithdrawalOrder>()
                .eq(HotelWithdrawalOrder.ORDER_NO, orderNo)
                .eq(HotelWithdrawalOrder.ORDER_TYPE, orderType).last("limit 1"));
        Arguments.beanIsNull(order, "该提现订单不存在");
        return order;
    }
}
